package com.xiaoq.sites.endpoint;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.xiaoq.sites.entity.*;
import io.swagger.annotations.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import com.xiaoq.coms.GenericListResponse;
import com.xiaoq.coms.GenericResponse;
import com.xiaoq.coms.util.IdGenerator;
import com.xiaoq.sites.service.IInfrastructureService;
import com.xiaoq.sites.service.ISitesService;
import com.xiaoq.sites.vo.SitesBusStationVo;
import com.xiaoq.sites.vo.SitesEntryVo;
import com.xiaoq.sites.vo.SitesFoodVo;
import com.xiaoq.sites.vo.SitesInfrastructureVo;
import com.xiaoq.sites.vo.SitesParkVo;
import com.xiaoq.sites.vo.SitesPierVo;
import com.xiaoq.sites.vo.SitesPoint2Vo;
import com.xiaoq.sites.vo.SitesRestZoneVo;
import com.xiaoq.sites.vo.SitesSeeingCarStationVo;
import com.xiaoq.sites.vo.SitesServiceCenterVo;
import com.xiaoq.sites.vo.SitesShopVo;
import com.xiaoq.sites.vo.SitesTelpherStationVo;
import com.xiaoq.sites.vo.SitesTicketOfficeVo;
import com.xiaoq.sites.vo.SitesToiletVo;
import com.xiaoq.sitesinfrastructure.util.InfraTypeUtil;

@RestController
@RequestMapping("/api/v1")
@Api(tags = "基础设施建设")
public class SitesInfrastructureEndpoint {
	
	private static final class SitesInfrastructureListResponse extends GenericListResponse<SitesInfrastructureVo> {};
	
	private static final class SitesToiletListResponse extends GenericListResponse<SitesToiletVo>{};
	
	private static final class SitesBusStationListResponse extends  GenericListResponse<SitesBusStationVo>{};
	
	private static final class SitesEntryListResponse extends GenericListResponse<SitesEntryVo>{};
	
	private static final class SitesParkListResponse extends GenericListResponse<SitesParkVo>{};
	
	private static final class SitesPierListResponse extends GenericListResponse<SitesPierVo>{};
	
	private static final class SitesRestZoneListResponse extends GenericListResponse<SitesRestZoneVo>{};
	
	private static final class SitesSeeingCarStationListResonse extends GenericListResponse<SitesSeeingCarStationVo>{};
	
	private static final class SitesServiceCenterListResponse extends GenericListResponse<SitesServiceCenterVo>{};
	
	private static final class SitesShopListResonse extends GenericListResponse<SitesShopVo>{};
	
	private static final class SitesTelpherStationListResponse extends GenericListResponse<SitesTelpherStationVo>{};
	
	private static final class SitesTicketOfficeListResponse extends GenericListResponse<SitesTicketOfficeVo>{};
	private static final class SitesFoodVoListResponse extends GenericListResponse<SitesFoodVo>{};
	
	@Autowired
	private IInfrastructureService infrastuctureApi;
	
	@Autowired
	private IdGenerator idGenerator;
	
	private static final Logger LOG = LoggerFactory.getLogger(SitesInfrastructureEndpoint.class);
	
	
	@ApiOperation(value="基础设施列表", notes="根据景区ID查询基础设施列表")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesInfrastructureListResponse.class, message = "基础设施列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesInfrastructureListBySitesIdAndInfraType(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "基础设施列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESINFRSTRUCTURE);
			
			
			List<SitesInfrastructureVo> sitesInfrastructureVoList = new ArrayList<>();
			SitesInfrastructureVo sitesInfrastructureVo = null;
			if(CollectionUtils.isNotEmpty(infraList)) {
				for (InfrastructureBaseEntity infrastructureBase : infraList) {
					sitesInfrastructureVo = new SitesInfrastructureVo();
					BeanUtils.copyProperties(infrastructureBase, sitesInfrastructureVo);
					sitesInfrastructureVoList.add(sitesInfrastructureVo);
				}
			}
			
			return SitesInfrastructureListResponse.listNoCount(sitesInfrastructureVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	


	
/**
 *   要给前端凸显不同接口的特性在 controller这里使用一个函数借口肯定是不行的
 *   只能给每中基建留下不同不同的借口，只需要在每个函数内部进行区分
 */

	@ApiOperation(value="公交车站列表", notes="根据景区ID查询公交车列表")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesBusStationListResponse.class, message = "公交车站列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/bus_station", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesBusStationBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "公交车站列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESBUSSTATIONTYPE );
			System.out.println(infraList.get(0).getClass());
			List<SitesBusStationEntity> sitesBusStationList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesBusStationList.add((SitesBusStationEntity)infra);
			}
			List<SitesBusStationVo> SitesBusStationVoList = new ArrayList<>();
			SitesBusStationVo sitesBusStationVo = null;
			if(CollectionUtils.isNotEmpty(sitesBusStationList)) {
				for (SitesBusStationEntity sitesBusStation : sitesBusStationList) {
					sitesBusStationVo = new SitesBusStationVo();
					BeanUtils.copyProperties(sitesBusStation, sitesBusStationVo);
					SitesBusStationVoList.add(sitesBusStationVo);
				}
			}
			
			return SitesToiletListResponse.listNoCount(SitesBusStationVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	
	@ApiOperation(value="出入口列表", notes="根据景区ID查询出入口")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesEntryListResponse.class, message = "出入口列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/entry", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesEntryBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "出入口列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESENTRYTYPE );
			
			List<SitesEntryEntity> sitesEntryList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesEntryList.add((SitesEntryEntity)infra);
			}
			List<SitesEntryVo> sitesEntryVoList = new ArrayList<>();
			SitesEntryVo sitesEntryVo = null;
			if(CollectionUtils.isNotEmpty(sitesEntryList)) {
				for (SitesEntryEntity sitesEntry : sitesEntryList) {
					sitesEntryVo = new SitesEntryVo();
					BeanUtils.copyProperties(sitesEntry, sitesEntryVo);
					sitesEntryVoList.add(sitesEntryVo);
				}
			}
			
			return SitesEntryListResponse.listNoCount(sitesEntryVoList);
		} catch (Exception e) {
			LOG.error(errorMsg, e);
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="对接运营后端（添加出入口信息）", notes="对接运营后端（添加出入口信息）")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesEntryListResponse.class, message = "对接运营后端（添加出入口信息）")
	})
	@PostMapping(value="/sites/entry", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> addSitesEntry(@RequestBody SitesEntryVo sitesEntryVo){
		SitesEntryEntity sitesEntry = new SitesEntryEntity();
		BeanUtils.copyProperties(sitesEntryVo, sitesEntry);
//		sitesEntry.setId(idGenerator.nextId());
		sitesEntry.setInfraType(5);
		infrastuctureApi.addSitesInfraType(sitesEntry);
		return GenericResponse.ok();
		
	}
	
	@ApiOperation(value="对接运营后端（修改出入口信息）", notes="对接运营后端（修改出入口信息）")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesEntryListResponse.class, message = "对接运营后端（修改出入口信息）")
	})
	@PutMapping(value="/sites/entry", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> updateSitesEntry(@RequestBody SitesEntryVo sitesEntryVo){
		String id = sitesEntryVo.getId();
		SitesEntryEntity sitesEntry = (SitesEntryEntity) infrastuctureApi.findInfraById(id);
		String name = sitesEntryVo.getName();
		if(StringUtils.isNotBlank(name)){
			sitesEntry.setName(name);
		}
		Double longitude = sitesEntryVo.getLongitude();
		if(longitude!=null&&longitude!=0){
			sitesEntry.setLongitude(longitude);
		}
		
		Double latitude = sitesEntryVo.getLatitude();
		if(latitude!=null&&latitude!=0){
			sitesEntry.setLatitude(latitude);
		}
		String sitesId = sitesEntryVo.getSitesId();
		if(StringUtils.isNotBlank(sitesId)){
			sitesEntry.setSitesId(sitesId);
		}
		String memo = sitesEntryVo.getMemo();
		if(StringUtils.isNotBlank(memo)){
			sitesEntry.setMemo(memo);
		}
		String code = sitesEntryVo.getCode();
		if(StringUtils.isNotBlank(code)){
			sitesEntry.setCode(code);
		}
		String openSchedule = sitesEntryVo.getOpenSchedule();
		if(StringUtils.isNotBlank(openSchedule)){
			sitesEntry.setOpenSchedule(openSchedule);
		}
		String inoutFlag = sitesEntryVo.getInoutFlag();
		if(StringUtils.isNotBlank(inoutFlag)){
			sitesEntry.setInoutFlag(inoutFlag);
		}
		String mainFlag = sitesEntry.getMainFlag();
		if(StringUtils.isNotBlank(mainFlag)){
			sitesEntry.setMainFlag(mainFlag);
		}
		infrastuctureApi.addSitesInfraType(sitesEntry);
		return GenericResponse.ok();
		
	}
	
	@ApiOperation(value="对接运营后端（删除出入口信息）", notes="对接运营后端（删除出入口信息）")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesEntryListResponse.class, message = "对接运营后端（删除出入口信息）")
	})
	@DeleteMapping(value="/sites/entry", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> deleteSitesEntry(@RequestParam(value="entryId",required=true)String entryId){
		infrastuctureApi.deleteSitesInfraType(entryId);
		return GenericResponse.ok();
		
	}
	
	@ApiOperation(value="停车场列表", notes="根据景区ID查询停车场")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesParkListResponse.class, message = "停车场列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/park", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesParkBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "停车场列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESPARKTYPE );
			
			List<SitesParkEntity> sitesParkList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesParkList.add((SitesParkEntity)infra);
			}
			List<SitesParkVo> sitesParkVoList = new ArrayList<>();
			SitesParkVo sitesParkVo = null;
			if(CollectionUtils.isNotEmpty(sitesParkList)) {
				for (SitesParkEntity sitesPark : sitesParkList) {
					sitesParkVo = new SitesParkVo();
					BeanUtils.copyProperties(sitesPark, sitesParkVo);
					sitesParkVoList.add(sitesParkVo);
				}
			}
			
			return SitesParkListResponse.listNoCount(sitesParkVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="游船码头列表", notes="根据景区ID查询游船码头")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesPierListResponse.class, message = "游船码头列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/pier", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesPierBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "游船码头列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESPIERTYPE );
			
			List<SitesPierEntity> sitesPierList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesPierList.add((SitesPierEntity)infra);
			}
			List<SitesPierVo> sitesPierVoList = new ArrayList<>();
			SitesPierVo sitesPierVo = null;
			if(CollectionUtils.isNotEmpty(sitesPierList)) {
				for (SitesPierEntity sitesPier : sitesPierList) {
					sitesPierVo = new SitesPierVo();
					BeanUtils.copyProperties(sitesPier, sitesPierVo);
					sitesPierVoList.add(sitesPierVo);
				}
			}
			
			return SitesPierListResponse.listNoCount(sitesPierVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="休息区列表", notes="根据景区ID查询休息区")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesRestZoneListResponse.class, message = "休息区列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/rest_zone", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesRestZoneBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "休息区列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESRESTZONETYPE );
			
			List<SitesRestZoneEntity> sitesRestZoneList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesRestZoneList.add((SitesRestZoneEntity)infra);
			}
			List<SitesRestZoneVo> sitesRestZoneVoList = new ArrayList<>();
			SitesRestZoneVo sitesRestZoneVo = null;
			if(CollectionUtils.isNotEmpty(sitesRestZoneList)) {
				for (SitesRestZoneEntity sitesRestZone : sitesRestZoneList) {
					sitesRestZoneVo = new SitesRestZoneVo();
					BeanUtils.copyProperties(sitesRestZone, sitesRestZoneVo);
					sitesRestZoneVoList.add(sitesRestZoneVo);
				}
			}
			
			return SitesRestZoneListResponse.listNoCount(sitesRestZoneVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="观光车站列表", notes="根据景区ID查询观光车站")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesSeeingCarStationListResonse.class, message = "观光车站列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/seeing_car_station", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesSeeingCarStationBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "观光车站列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESSEEINGCARSTATIONTYPE );
			
			List<SitesSeeingCarStationEntity> sitesSeeingCarStationList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesSeeingCarStationList.add((SitesSeeingCarStationEntity)infra);
			}
			List<SitesSeeingCarStationVo> sitesSeeingCarStationVoList = new ArrayList<>();
			SitesSeeingCarStationVo sitesSeeingCarStationVo = null;
			if(CollectionUtils.isNotEmpty(sitesSeeingCarStationList)) {
				for (SitesSeeingCarStationEntity sitesSeeingCarStation : sitesSeeingCarStationList) {
					sitesSeeingCarStationVo = new SitesSeeingCarStationVo();
					BeanUtils.copyProperties(sitesSeeingCarStation, sitesSeeingCarStationVo);
					sitesSeeingCarStationVoList.add(sitesSeeingCarStationVo);
				}
			}
			
			return SitesSeeingCarStationListResonse.listNoCount(sitesSeeingCarStationVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="服务中心列表", notes="根据景区ID查询服务中心")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesServiceCenterListResponse.class, message = "服务中心列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/service_center", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesServiceCenterBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "服务中心列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESSERVICECENTERTYPE );
			
			List<SitesServiceCenterEntity> sitesServiceCenterList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesServiceCenterList.add((SitesServiceCenterEntity)infra);
			}
			List<SitesServiceCenterVo> sitesServiceCenterVoList = new ArrayList<>();
			SitesServiceCenterVo sitesServiceCenterVo = null;
			if(CollectionUtils.isNotEmpty(sitesServiceCenterList)) {
				for (SitesServiceCenterEntity sitesServiceCenter : sitesServiceCenterList) {
					sitesServiceCenterVo = new SitesServiceCenterVo();
					BeanUtils.copyProperties(sitesServiceCenter, sitesServiceCenterVo);
					sitesServiceCenterVoList.add(sitesServiceCenterVo);
				}
			}
			
			return SitesServiceCenterListResponse.listNoCount(sitesServiceCenterVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="商品部列表", notes="根据景区ID查询商品部")
	@ApiResponses({
		@ApiResponse(code = 200, response =SitesShopListResonse.class, message = "商品部列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/shop", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?>siteShopBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "商品部列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESSHOPTYPE );
			
			List<SitesShopEntity> sitesShopList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesShopList.add((SitesShopEntity)infra);
			}
			List<SitesShopVo> sitesShopVoList = new ArrayList<>();
			SitesShopVo sitesShopVo = null;
			if(CollectionUtils.isNotEmpty(sitesShopList)) {
				for (SitesShopEntity sitesShop : sitesShopList) {
					sitesShopVo = new SitesShopVo();
					BeanUtils.copyProperties(sitesShop, sitesShopVo);
					sitesShopVoList.add(sitesShopVo);
				}
			}
			
			return SitesShopListResonse.listNoCount(sitesShopVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="缆车站列表", notes="根据景区ID查询缆车站")
	@ApiResponses({
		@ApiResponse(code = 200, response =SitesTelpherStationListResponse.class, message = "缆车站列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/telpher_station", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?>sitesTelpherBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "缆车站列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESTELPHERSTATIONTYPE);
			
			List<SitesTelpherStationEntity> sitesTelpherStationList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesTelpherStationList.add((SitesTelpherStationEntity)infra);
			}
			List<SitesTelpherStationVo> sitesTelpherStationVoList = new ArrayList<>();
			SitesTelpherStationVo sitesTelpherStationVo = null;
			if(CollectionUtils.isNotEmpty(sitesTelpherStationList)) {
				for (SitesTelpherStationEntity sitesTelpherStation : sitesTelpherStationList) {
					sitesTelpherStationVo = new SitesTelpherStationVo();
					BeanUtils.copyProperties(sitesTelpherStation, sitesTelpherStationVo);
					sitesTelpherStationVoList.add(sitesTelpherStationVo);
				}
			}
			
			return SitesTelpherStationListResponse.listNoCount(sitesTelpherStationVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="售票处列表", notes="根据景区ID查询售票处")
	@ApiResponses({
		@ApiResponse(code = 200, response =SitesTicketOfficeListResponse.class, message = "售票处列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/ticket_office", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?>sitesTicketOfficeBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "售票处列表出错";
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESTICKETOFFICETYPE );
			
			List<SitesTicketOfficeEntity> sitesTicketOfficeList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesTicketOfficeList.add((SitesTicketOfficeEntity)infra);
			}
			List<SitesTicketOfficeVo> sitesTicketOfficeVoList = new ArrayList<>();
			SitesTicketOfficeVo sitesTicketOfficeVo = null;
			if(CollectionUtils.isNotEmpty(sitesTicketOfficeList)) {
				for (SitesTicketOfficeEntity sitesTicketOffice : sitesTicketOfficeList) {
					sitesTicketOfficeVo = new SitesTicketOfficeVo();
					BeanUtils.copyProperties(sitesTicketOffice, sitesTicketOfficeVo);
					sitesTicketOfficeVoList.add(sitesTicketOfficeVo);
				}
			}
			
			return SitesTicketOfficeListResponse.listNoCount(sitesTicketOfficeVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
	}
	
	@ApiOperation(value="厕所列表", notes="根据景区ID查询厕所列表")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "厕所列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/toilet", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesToiletListBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "厕所列表出错";
		
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESTOILLETTYPE );
			
			List<SitesToiletEntity> sitesToiletList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				 sitesToiletList.add((SitesToiletEntity)infra);
			}
			List<SitesToiletVo> sitesToiletVoList = new ArrayList<>();
			SitesToiletVo sitesToileVo = null;
			if(CollectionUtils.isNotEmpty(sitesToiletList)) {
				for (SitesToiletEntity sitesToilet : sitesToiletList) {
					sitesToileVo = new SitesToiletVo();
					BeanUtils.copyProperties(sitesToilet, sitesToileVo);
					sitesToiletVoList.add(sitesToileVo);
				}
			}
			
			return SitesToiletListResponse.listNoCount(sitesToiletVoList);
		} catch (Exception e) {
			LOG.error(e.getMessage(),e);
			return GenericResponse.ng(errorMsg);
		}
		
	}
	
	@ApiOperation(value="运营后端对接（添加厕所接口）", notes="运营后端对接（添加厕所接口）")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "运营后端对接（添加厕所接口）")
	})
	@PostMapping(value="/sites/toilet", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> addsitesToilet(@RequestBody SitesToiletVo sitesToiletVo){
		SitesToiletEntity sitesToilet = new SitesToiletEntity();
		BeanUtils.copyProperties(sitesToiletVo, sitesToilet);
//		sitesToilet.setId(idGenerator.nextId());
		sitesToilet.setInfraType(1);
		infrastuctureApi.addSitesInfraType(sitesToilet);
		return GenericResponse.ok();
		
	}

	@ApiOperation(value="添加派出所", notes="添加派出所")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "添加派出所")
	})
	@PostMapping(value="/sites/paichu", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> addsitesPaichu(@RequestBody SitesPaichuEntity sitesPaichu){

		sitesPaichu.setId(idGenerator.nextId());
		sitesPaichu.setInfraType(InfraTypeUtil.SITESPAICHUTYPE);
		infrastuctureApi.addSitesInfraType(sitesPaichu);
		return GenericResponse.ok();

	}

	@ApiOperation(value="获取派出所", notes="获取派出所")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "获取派出所")
	})
	@GetMapping(value="/sites/paichu", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> getsitesPaichu(@RequestParam(value = "cityCode") String cityCode){

		List infras = infrastuctureApi.findSitesInfraTypeByCityCode(cityCode,InfraTypeUtil.SITESPAICHUTYPE);
		return GenericListResponse.listNoCount(infras);

	}

	@ApiOperation(value="获取基础设施", notes="获取基础设施")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "获取基础设施")
	})
	@GetMapping(value="/sites/infra", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> getSitesInfra(@RequestParam(value = "cityCode") String cityCode,@RequestParam(value = "infraType") Integer infraType){
		List infras = infrastuctureApi.findSitesInfraTypeByCityCode(cityCode,infraType);
		return GenericListResponse.listNoCount(infras);

	}

	@ApiOperation(value="添加基础设施", notes="添加基础设施")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "添加基础设施")
	})
	@PostMapping(value="/sites/infra", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> addSitesInfra(@RequestBody SitesPaichuEntity sitesPaichu){
		sitesPaichu.setId(idGenerator.nextId());
		infrastuctureApi.addSitesInfraType(sitesPaichu);
		return GenericResponse.ok();

	}


	@ApiOperation(value="添加卫生院", notes="添加卫生院")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "添加卫生院")
	})
	@PostMapping(value="/sites/weisheng", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> addsitesPaichu(@RequestBody SitesWeishengEntity sitesWeisheng){

		sitesWeisheng.setId(idGenerator.nextId());
		sitesWeisheng.setInfraType(InfraTypeUtil.SITESWEISHENGTYPE);
		infrastuctureApi.addSitesInfraType(sitesWeisheng);
		return GenericResponse.ok();

	}

	@ApiOperation(value="获取卫生院", notes="获取卫生院")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "获取卫生院")
	})
	@GetMapping(value="/sites/weisheng", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> getsitesWeisheng(@RequestParam(value = "cityCode") String cityCode){

		List infras = infrastuctureApi.findSitesInfraTypeByCityCode(cityCode,InfraTypeUtil.SITESWEISHENGTYPE);
		return GenericListResponse.listNoCount(infras);

	}


	@ApiOperation(value="添加加油站", notes="添加卫生院")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "添加卫生院")
	})
	@PostMapping(value="/sites/jiayou", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> addsitesPaichu(@RequestBody SitesJiayouEntity sitesJiayou){

		sitesJiayou.setId(idGenerator.nextId());
		sitesJiayou.setInfraType(InfraTypeUtil.SITESJIAYOUTYPE);
		infrastuctureApi.addSitesInfraType(sitesJiayou);
		return GenericResponse.ok();

	}

	@ApiOperation(value="获取加油站", notes="获取加油站")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "获取加油站")
	})
	@GetMapping(value="/sites/jiayou", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> getsitesJiayou(@RequestParam(value = "cityCode") String cityCode){

		List infras = infrastuctureApi.findSitesInfraTypeByCityCode(cityCode,InfraTypeUtil.SITESJIAYOUTYPE);
		return GenericListResponse.listNoCount(infras);

	}


	@ApiOperation(value="删除基础设施", notes="删除基础设施")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "删除基础设施")
	})
	@DeleteMapping(value="/sites/infra", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> deletesitesJiayou(@RequestParam(value = "id") String id){

		infrastuctureApi.deleteSitesInfraType(id);
		return GenericResponse.ok();

	}

	@ApiOperation(value="修改基础设施", notes="修改基础设施")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "修改基础设施")
	})
	@PutMapping(value="/sites/infra", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> updatesitesPaichu(@RequestBody SitesPaichuEntity sitesPaichu){

		infrastuctureApi.addSitesInfraType(sitesPaichu);
		return GenericResponse.ok();

	}
	
	@ApiOperation(value="运营后端对接（修改厕所接口）", notes="运营后端对接（修改厕所接口）")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "运营后端对接（修改厕所接口）")
	})
	@PutMapping(value="/sites/toilet", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> updateSitesToilet(@RequestBody SitesToiletVo sitesToiletVo){
		String id = sitesToiletVo.getId();
		SitesToiletEntity sitesToilet = (SitesToiletEntity) infrastuctureApi.findInfraById(id);
		String name = sitesToiletVo.getName();
		if(StringUtils.isNotBlank(name)){
			sitesToilet.setName(name);
		}
		Double longitude = sitesToiletVo.getLongitude();
		if(longitude!=null&&longitude!=0){
			sitesToilet.setLongitude(longitude);
		}
		
		Double latitude = sitesToiletVo.getLatitude();
		if(latitude!=null&&latitude!=0){
			sitesToilet.setLatitude(latitude);
		}
		
		String sitesId = sitesToiletVo.getSitesId();
		if(StringUtils.isNotBlank(sitesId)){
			sitesToilet.setSitesId(sitesId);
		}
		
		String imgUrl = sitesToiletVo.getImgUrl();
		if(StringUtils.isNotBlank(imgUrl)){
			sitesToilet.setImgUrl(imgUrl);
		}
		
		String memo = sitesToiletVo.getMemo();
		if(StringUtils.isNotBlank(memo)){
			sitesToilet.setMemo(memo);
		}
		infrastuctureApi.addSitesInfraType(sitesToilet);
		return GenericResponse.ok();
		
	}
	
	
	@ApiOperation(value="运营后端对接（删除厕所接口）", notes="运营后端对接（删除厕所接口）")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "运营后端对接（删除厕所接口）")
	})
	@DeleteMapping(value="/sites/toilet", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> deleteSitesToilet(@RequestParam(value="toiletId",required=true)String toiletId){
		infrastuctureApi.deleteSitesInfraType(toiletId);
		return GenericResponse.ok();
		
	}
	
	@ApiOperation(value="餐饮列表", notes="根据景区ID查询餐饮列表")
	@ApiResponses({
		@ApiResponse(code = 200, response = SitesFoodVoListResponse.class, message = "餐饮列表")
	})
	@GetMapping(value="/sites/{sitesId}/infrastructure/food", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> sitesFoodListBySites(@PathVariable("sitesId") @ApiParam(value="sitesId", required=true) String sitesId) {
		String errorMsg = "餐饮列表出错";
		
		try {
			List<InfrastructureBaseEntity> infraList = infrastuctureApi.findSitesInfraType(sitesId,InfraTypeUtil.SITESFOOTTYPE );
			
			List<SitesFoodEntity> sitesFootList = new ArrayList<>();
			for(InfrastructureBaseEntity infra: infraList){
				
				sitesFootList.add((SitesFoodEntity)infra);
			}
			List<SitesFoodVo> sitesFoodVoList = new ArrayList<>();
			SitesFoodVo sitesFoodVo = null;
			if(CollectionUtils.isNotEmpty(sitesFootList)) {
				for (SitesFoodEntity sitesFood : sitesFootList) {
					sitesFoodVo = new SitesFoodVo();
					BeanUtils.copyProperties(sitesFood, sitesFoodVo);
					sitesFoodVoList.add(sitesFoodVo);
				}
			}
			
			return SitesToiletListResponse.listNoCount(sitesFoodVoList);
		} catch (Exception e) {
			e.printStackTrace();
			return GenericResponse.ng(errorMsg);
		}
		
	}



	@ApiOperation(value="获取类别", notes="获取类别")
	@ApiResponses({
			@ApiResponse(code = 200, response = SitesToiletListResponse.class, message = "获取类别")
	})
	@GetMapping(value="/sites/catalog", produces={MediaType.APPLICATION_JSON_UTF8_VALUE})
	public ResponseEntity<?> getsitesCatalog(){

		List list = new ArrayList();
		Map map = new HashMap();
		map.put("infraType","1");
		map.put("type","洗手间");
		list.add(map);


		map = new HashMap();
		map.put("infraType","4");
		map.put("type","停车场");
		list.add(map);

		map = new HashMap();
		map.put("infraType","5");
		map.put("type","出入口");
		list.add(map);


		map = new HashMap();
		map.put("infraType","13");
		map.put("type","派出所");
		list.add(map);

		map = new HashMap();
		map.put("infraType","14");
		map.put("type","卫生院");
		list.add(map);

		map = new HashMap();
		map.put("infraType","15");
		map.put("type","加油站");
		list.add(map);
		return GenericListResponse.listNoCount(list);

	}
	
	
	
	
	
	
}
